package net.wantongtech.xa.uploadbasicinfo.dao;

import com.wtkj.dao.impl.BaseDataTemplate;
import com.wtkj.dao.impl.GenericResultSetExtractor;
import com.wtkj.vo.dzzf.base.kfwd.CardInfo;
import com.wtkj.vo.dzzf.base.qxsjz.entity.MergeTransLog;
import com.wtkj.vo.dzzf.base.qxsjz.entity.PortalTransOut;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 处理错误的合并交易DAO
 *
 * @author MaShibo
 * 日期 :  2020/2/19
 */
@Repository
public class ProcessErrorMergeTransDao extends BaseDataTemplate {

    public List<MergeTransLog> queryMergeTransLogInfo() {
        final String sql = "SELECT * from tr_merge_log a WHERE a.error LIKE '%签约来源不一致%'";
        return jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(MergeTransLog.class));
    }

    public List<PortalTransOut> queryPortalTransOutByPassId(String passId) {
        final String sql = "SELECT * FROM tr_portal_transout tr WHERE tr.passid = ?";
        return jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(PortalTransOut.class), passId);
    }

    public CardInfo queryCardInfoByCardNo(String eCardNo) {
        final String sql = "SELECT * FROM ac_cardinfo a WHERE a.ecardno = ?";
        List<CardInfo> cardInfoList = jdbcTemplate.query(sql, GenericResultSetExtractor.getInstance(CardInfo.class), eCardNo);
        return cardInfoList.isEmpty() ? null : cardInfoList.get(0);
    }

    public int updateSignSourceToNull(String transactionId) {
        final String sql = "UPDATE tr_portal_transout tr set tr.signsource=null where tr.transactionId=?";
        return jdbcTemplate.update(sql, transactionId);
    }
}
